import axios from '@/utils/request';


/**
 * 获取省市区数据
 */
 export async function GetRegionsData() {
  const res = await axios.get('/RegionData/GetCurrentRegionData');
  if (res.data.code === 200) {
    return JSON.parse(res.data.data) ;
  }
  return Promise.reject(new Error(res.data.msg));
}



/**
 * 获取当前组织架构下所有的子节点
 */
export async function QueryCurrentChildOrganiztion(organiztionId) {
  const res = await axios.get('/Organiztion/QueryCurrentChildOrganiztion?organiztionId='+organiztionId);
  if (res.data.code === 200) {
    return res.data.data;
  }
  return Promise.reject(new Error(res.data.msg));
}


/**
 * 获取当前组织架构下所有分公司的子节点
 */
export async function QueryCurrentChildCompanyOrganiztion() {
  const res = await axios.get('/Organiztion/QueryCurrentChildCompanyOrganiztion');
  if (res.data.code === 200) {
    return res.data.data;
  }
  return Promise.reject(new Error(res.data.msg));
}

/**
 * 获取树结构的组织架构数据集
 */
export async function QueryTreeOrganiztion() {
  const res = await axios.post('/Organiztion/QueryTreeOrganiztion');
  if (res.data.code === 200) {
    return res.data.data;
  }
  return Promise.reject(new Error(res.data.msg));
}

/**
 * 获取组织树形结构
 */
export async function QueryTreeView() {
  const res = await axios.post('/Organiztion/QueryTreeView');
  if (res.data.code === 200) {
    return res.data.data;
  }
  return Promise.reject(new Error(res.data.msg));
}

/**
 * 查询当前公司组织架构
 */
export async function QueryCurrentOrganiztion() {
  const res = await axios.post('/Organiztion/QueryCurrentOrganiztion');
  if (res.data.code === 200) {
    return res.data.data;
  }
  return Promise.reject(new Error(res.data.msg));
}

/**
 * 根据组织Id查询当前公司组织架构
 */
 export async function QueryOrganiztionById(id) {
    const res = await axios.get('/Organiztion/QueryOrganiztionById?id='+id);
    if (res.data.code === 200) {
      return res.data.data;
    }
    return Promise.reject(new Error(res.data.msg));
  }
  
  
 /**
 * 新增组织构架,初始化数据组织架构(Id,Code,Level,orgId)、公司
 */
export async function AddOrganizational(params) {
  const res = await axios.post('/Organiztion/AddOrganizational',params);
  if (res.data.code === 200) {
    return res.data.msg;
  }
  return Promise.reject(new Error(res.data.msg));
}

/**
 * 更新组织构架
*/
export async function UpdateOrganizational(params) {
    const res = await axios.post('/Organiztion/UpdateOrganizational',params);
    if (res.data.code === 200) {
      return res.data.msg;
    }
    return Promise.reject(new Error(res.data.msg));
  }
  
  /**
 * 删除组织构架
 */
export async function DeleteOrganiztion(id) {
    const res = await axios.post('/Organiztion/DeleteOrganiztion?id='+id);
    if (res.data.code === 200) {
      return res.data.msg;
    }
    return Promise.reject(new Error(res.data.msg));
  }


  
